﻿
-----------------------------------------------------------------------
-- MatrixWidget.lua
--
-- A Framework for World Of Warcraft addons
-- Copyright (C) 2007  wwkkii
-- 
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
-- 
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-- 
-- Home Page: http://code.google.com/p/wowmatrix
-----------------------------------------------------------------------

local __version__ = { "MatrixWidget", 0, 1, 1 };
if (MatrixUpdateVersion(__version__)) then return; end

-------------------------------------------------------------------------------
-- local variables
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- MatrixWidget Class
-------------------------------------------------------------------------------

MatrixClass("MatrixWidget", MatrixObject, MATRIX_CLASS);

function MatrixWidget:FromHandle(id)
	local name, node;

	name = id:GetName();
	if (not matrix.IsKeyName(name)) then
		name = "MATRIX_NONAME";
	end
	if (id.__matrix__) then
		matrix.Crash("ERROR_MULTIPLE_ATTACH", name, id);
	end
	node = MatrixWidget:New(name);
	if (node) then
		node.__handle__ = id;
		id.__matrix__ = node;
	end
	return node;
end

function MatrixWidget:Create(tag, parent, temp)
	if (self.__handle__) then
		self:Crash("ERROR_MULTIPLE_CREATE", self:Name());
	end
	self.__handle__ = CreateFrame(tag, nil, parent, temp);
	if (self.__handle__) then
		self.__handle__.__matrix__ = self;
	end
end

function MatrixWidget:SetAllPoints(frame)
	if (matrix.IsObject(frame) and frame:Match(MatrixWidget)) then
		frame = frame:Handle();
	end
	self.__handle__:SetAllPoints(frame);
end
